SCRIPT_DIR=$(dirname "$(realpath "$BASH_SOURCE")")
export ZDOTDIR="$SCRIPT_DIR"

# 检查系统zsh是否安装
check_zsh_installed() {
    # 检查zsh是否存在
    if command -v zsh >/dev/null 2>&1; then
        return 0  # zsh已安装
    else
        return 1  # zsh未安装
    fi
}

if check_zsh_installed; then
# 执行替换
    ZSH_PATH=$(which zsh)
    if sed -i.bak \
        -e "s|{PATH_PLACEHOLDER1}|${SCRIPT_DIR}|g" "${SCRIPT_DIR}/tmux.conf" \
        -e "s|{PATH_PLACEHOLDER2}|${ZSH_PATH}|g";
    then
        echo "✓ tmux.conf 替换完成!请享受tmux!"
        echo "备份文件: ${SCRIPT_DIR}/tmux.conf.bak"
    fi
else
    if command -v ${SCRIPT_DIR}/software/bin/zsh >/dev/null 2>&1; then
        echo "✓ 检测到自编译z shell!"
    else
        echo "z shell未安装...请安装z shell..."
        exit 1
    fi
    
    if sed -i.bak \
        -e "s|{PATH_PLACEHOLDER1}|${SCRIPT_DIR}|g" "${SCRIPT_DIR}/tmux.conf" \
        -e "s|{PATH_PLACEHOLDER2}|${SCRIPT_DIR}/software/bin/zsh|g";
    then
        echo "✓ tmux.conf 替换完成!请享受tmux!"
        echo "备份文件: ${SCRIPT_DIR}/tmux.conf.bak"
    fi
fi

if check_zsh_installed; then
    exec ${ZSH_PATH} -l
else
    exec $SCRIPT_DIR/software/bin/zsh -l
fi

